package com.sdry.service.hpf;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sdry.dao.hpf.ProjectInfoMapper;
import com.sdry.entity.hpf.ProjectInfo;
import com.sdry.utils.PageBean;

/**
 * @ClassName: ProjectInfoServiceImpl 
 * @Description:项目信息Service
 * @Author hpf
 * @Date 2018年4月25日 下午2:43:13 
 * @version 1.0
 */
@Service
@Transactional
public class ProjectInfoServiceImpl implements ProjectInfoService {

	@Resource
	private ProjectInfoMapper projectInfoMapper;
	
	@Override
	public ProjectInfo queryById(Long id) {
		return projectInfoMapper.queryById(id);
	}

	@Override
	public List<ProjectInfo> queryAll(Map map) {
		return projectInfoMapper.find(map);
	}

	@Override
	public List<ProjectInfo> findPage(PageBean pageBean) {
		return projectInfoMapper.findPage(pageBean);
	}

	@Override
	public Integer selectCount(PageBean pageBean) {
		return projectInfoMapper.selectCount(pageBean);
	}

	@Override
	public ProjectInfo selectByPrimaryKey(Serializable id) {
		return null;
	}

	@Override
	public Integer insert(ProjectInfo projectInfo) {
		return projectInfoMapper.insert(projectInfo);
	}

	@Override
	public Integer update(ProjectInfo projectInfo) {
		return projectInfoMapper.update(projectInfo);
	}

	@Override
	public Integer deleteById(Long id) {
		return projectInfoMapper.deleteById(id);
	}

	@Override
	public Integer delete(Serializable[] ids) {
		return projectInfoMapper.delete(ids);
	}

	@Override
	public String projectInfoNumLast() {
		
		String returnNumber = "";
        String returnNumberDate = "";
        DateFormat format = new SimpleDateFormat("yyyyMMdd");
        returnNumberDate = format.format(new Date());
        returnNumber = "P" + returnNumberDate + "00001";

        for (int i = 1; i <= 99999; i++) {

            int dedaoNumber = projectInfoMapper.checkNumUnique(returnNumber);
            if (dedaoNumber == 0) {
                break;
            } else {
                switch (String.valueOf(i).length()) {
                    case 1:
                        returnNumber = "P" + returnNumberDate + "0000" + i;
                        break;
                    case 2:
                        returnNumber = "P" + returnNumberDate + "000" + i;
                        break;
                    case 3:
                        returnNumber = "P" + returnNumberDate + "00" + i;
                        break;
                    case 4:
                        returnNumber = "P" + returnNumberDate + "0" + i;
                        break;
                    case 5:
                        returnNumber = "P" + returnNumberDate + i;
                        break;
                    default:
                        returnNumber = "P" + returnNumberDate + "1000" + i;
                        break;
                }
            }
        }
        return returnNumber;
	}

}
